package com.example.stumanager.config;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import com.example.stumanager.HomepageLoginInterface;
import com.example.stumanager.R;
import com.example.stumanager.database.UserSql;
import com.example.stumanager.entity.UserEntity;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 启动类
 */
public class Start extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }

        //设置默认管理员信息
        UserSql db = new UserSql(this);
        ArrayList<UserEntity> dbAll = db.getAll();
        UserSql u = new UserSql(getBaseContext());
        if (dbAll.size() == 0) {
            u.add(new UserEntity("lhm", "系统管理员", "123456", "", "", 0));
            u.add(new UserEntity("1", "系统管理员", "1", "", "", 0));
        }


        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                startActivity(new Intent(Start.this, HomepageLoginInterface.class));
                finish();
            }
        };
        timer.schedule(timerTask, 2000);
    }
}